package com.swpu.project.util;

import java.util.HashMap;
import java.util.Map;

public class NumberUtil {

    static  Map<Character, Integer> chineseToArabicMap;
    static {

        chineseToArabicMap = new HashMap<>();
        chineseToArabicMap.put('零', 0);
        chineseToArabicMap.put('一', 1);
        chineseToArabicMap.put('二', 2);
        chineseToArabicMap.put('三', 3);
        chineseToArabicMap.put('四', 4);
        chineseToArabicMap.put('五', 5);
        chineseToArabicMap.put('六', 6);
        chineseToArabicMap.put('七', 7);
        chineseToArabicMap.put('八', 8);
        chineseToArabicMap.put('九', 9);
    }
static  String chineseToNumber(String target)
{
    if(!isChinese(target))
    return target;




    StringBuilder arabicNumber = new StringBuilder();
    for (char c : target.toCharArray()) {
        if (chineseToArabicMap.containsKey(c)) {
            arabicNumber.append(chineseToArabicMap.get(c));
        } else {
            arabicNumber.append(c);
        }
    }
    return arabicNumber.toString();



}





static boolean isChinese(String t)
{
    char c = t.charAt(0);
    if (chineseToArabicMap.get(c)==null)
        return false;

    return true;
}

public static String findNumber(String blockNum)
{
    int i = blockNum.indexOf("号");
    if(i==-1)
        return null;
    String substring = blockNum.substring(0, i);

    return chineseToNumber(substring);
}

}
